package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.BNitreEmission;
import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.carbon.service.IBNitreEmissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 脱硝排放Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/nitre/emission")
public class BNitreEmissionController extends BaseController
{
    @Autowired
    private IBNitreEmissionService bNitreEmissionService;

    /**
     * 查询脱硝排放列表
     */
    //  @PreAuthorize("@ss.hasPermi('nitre:emission:list')")
    @GetMapping("/list")
    public TableDataInfo list(BNitreEmission bNitreEmission)
    {
        startPage();
        List<BNitreEmission> list = bNitreEmissionService.selectBNitreEmissionList(bNitreEmission);
        return getDataTable(list);
    }

    /**
     * 脱硝排放计算
     */
    @GetMapping("/calNitreEmission")
    public AjaxResult calNitreEmission(@RequestParam Long projectId) {
        return bNitreEmissionService.calNitreEmission(projectId);
    }

    /**
     * 导出脱硝排放列表
     */
    //  @PreAuthorize("@ss.hasPermi('nitre:emission:export')")
    @Log(title = "脱硝排放", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BNitreEmission bNitreEmission)
    {
        List<BNitreEmission> list = bNitreEmissionService.selectBNitreEmissionList(bNitreEmission);
        ExcelUtil<BNitreEmission> util = new ExcelUtil<BNitreEmission>(BNitreEmission.class);
        return util.exportExcel(list, "emission");
    }

    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return bNitreEmissionService.changeDataByProjectId(excel);
    }


    /**
     * 获取脱硝排放详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('nitre:emission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bNitreEmissionService.selectBNitreEmissionById(id));
    }

    /**
     * 新增脱硝排放
     */
    //  @PreAuthorize("@ss.hasPermi('nitre:emission:add')")
    @Log(title = "脱硝排放", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BNitreEmission bNitreEmission)
    {
        return toAjax(bNitreEmissionService.insertBNitreEmission(bNitreEmission));
    }

    /**
     * 修改脱硝排放
     */
    //  @PreAuthorize("@ss.hasPermi('nitre:emission:edit')")
    @Log(title = "脱硝排放", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BNitreEmission bNitreEmission)
    {
        return toAjax(bNitreEmissionService.updateBNitreEmission(bNitreEmission));
    }

    /**
     * 删除脱硝排放
     */
    //  @PreAuthorize("@ss.hasPermi('nitre:emission:remove')")
    @Log(title = "脱硝排放", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bNitreEmissionService.deleteBNitreEmissionByIds(ids));
    }
}
